import $ from 'jquery'

class Ajax {
    send(type,url,data) {
        try{
            return new Promise((resolve,reject) => {
                $.ajax({
                    type: type,
                    url: url,
                    timeout: 30000,
                    dataType: 'json',
                    data: data,
                    success: function(res) {
                        return resolve(res);
                    },
                    error: function(xhr,textStatus) {
                        return reject(xhr.responseText);
                    }
                });
            });
        } catch(e) {
            console.log('Ajax Error: ',e);
        }
    }

}

export default {

    post: function(url,data) {
        return new Ajax().send('post',url,data);
    },

    get: function(url) {
        return new Ajax().send('get',url,null);
    }
}